package com.liuql.openapiinterface.controller;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpUtil;
import org.apache.commons.lang3.StringUtils;
import com.liu.openapiclientsdk.model.User;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 查询名称API
 *
 * @author liuql
 */

@RestController
@RequestMapping("/name")
public class NameController {

    @GetMapping("/")
    public String getNameByGet(String name) {
        return "GET 你的名字是" + name;
    }

    @PostMapping("/")
    public String getNameByPost(@RequestParam String name){
        return "POST 你的名字是" + name;
    }

    @PostMapping("/user")
    public String getUsernameByPost(@RequestBody User user, HttpServletRequest request){
        System.out.println(user.getName());
        return "POST 用户名字是" + user.getName();
    }



    @GetMapping("/three/sentences/interface")
    public String threeSentences(HttpServletRequest request){

        String result = HttpUtil.get("https://api.apiopen.top/api/sentences"
                , CharsetUtil.CHARSET_UTF_8);
        if (StringUtils.isBlank(result)){
            return "此接口发生了意外55！！";
        }
        return result;
    }




}
